package com.example.myproject;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.gif.GifDrawable;

import java.io.IOException;
import java.io.InputStream;

import pl.droidsonroids.gif.GifImageView;

/**
 * gif 没有暂停播放的功能
 *
 */
public class GifActivity extends AppCompatActivity implements View.OnClickListener {

    private Button but_playgif;
    private ImageView iv_gif_show;
    private GifImageView gif;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gif);

        iv_gif_show = findViewById(R.id.iv_gif_show);
        but_playgif = findViewById(R.id.but_playgif);

//        gif = findViewById(R.id.gifiv_show);

//        InputStream stream = getResources().openRawResource(R.raw.timg_gif);
//        try {
//            pl.droidsonroids.gif.GifDrawable gifDrawable = new pl.droidsonroids.gif.GifDrawable(stream);
//            gif.setImageDrawable(gifDrawable);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        but_playgif.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.but_playgif:
                //清空 缓存，最后试一次，是否现在播放gif已经不需要 增加gif 格式设定了
                //  确定，当前版本的 gif播放已经不需要专门设定gif格式了
                RequestManager manager = Glide.with(GifActivity.this);
                manager.load(R.raw.timg_gif).into(iv_gif_show);

                //停止 gif播放呢？
                break;
            default:

                break;
        }
    }
}
